package com.app.ytong.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Build;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import com.app.ytong.R;

import my.DisplayUtil;

/**
 * 
 * @author Android将军
 *
 */
@SuppressLint("NewApi")
public class KeyPwdNumView extends LinearLayout{


	private EditText mEditText;
	private LinearLayout mLinearLayout;

	private String mContent = "000";

	private int width;
	private int height;
	private int marginLeft;

//	private TextView text_one;
//	private TextView text_two;
//	private TextView text_three;


	@SuppressLint("NewApi") public KeyPwdNumView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);



	}
	public KeyPwdNumView(Context context) {
		super(context);


	}

	public KeyPwdNumView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mLinearLayout = new LinearLayout(context);
		mLinearLayout.setOrientation(HORIZONTAL);
		mLinearLayout.setGravity(Gravity.CENTER_VERTICAL);
		addView(mLinearLayout);
		width = DisplayUtil.dip2px(context,40);
		height = width;
		marginLeft = DisplayUtil.dip2px(context,10);
		resetView();
	}

	public void setString(String content){
		this.mContent = content;
		resetView();
	}

	@RequiresApi(api = Build.VERSION_CODES.M)
	public void resetView(){
		mLinearLayout.removeAllViews();
		if(TextUtils.isEmpty(mContent))return;
		for(int i = 0 , l = mContent.length(); i < l ; i ++){
			String item = mContent.substring(i,i+1);

			TextView textView = new TextView(getContext());
			textView.setWidth(width);
			textView.setHeight(height);
			textView.setGravity(Gravity.CENTER);
			textView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));//加粗
			textView.setBackgroundResource(R.drawable.base_blue_bg_corner);
			textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,24);
			textView.setTextColor(getContext().getColor(R.color.white));
			textView.setText(item);
            mLinearLayout.addView(textView);

			if(i > 0){
				LayoutParams params = (LayoutParams) textView.getLayoutParams();
				params.setMargins(marginLeft,0,0,0);
				textView.setLayoutParams(params);
			}


		}
	}
}
